package Psy_Admin_Page;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class ConsultantPage extends StaffPage {
    //获取咨询师状态
    @Override
    public String getState() {
        waitForWindow(2000);
        //默认是第一个用户的状态
        WebElement element =  driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(7) > div:nth-child(1)"));
        return element.getText();
    }

    @Override
    //点击修改信息
    public ConsultantPage clickEdit(){
        waitForWindow(2000);
        driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(8) > div:nth-child(1) > div:nth-child(1) > button:nth-child(1)")).click();
        return this;
    }

    @Override
    //输入工作单位
    public StaffPage inputWorkPlace(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[10]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[10]")).sendKeys(keys);
        return this;
    }

    //修改咨询师的工作单位
    @Override
    public ConsultantPage editWorkplace(String keys) {
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[10]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputWorkPlace(keys).confirmAdd();
        return this;
    }

    @Override
    //获取工作单位
    public String getWorkplace(){
        clickEdit();
        waitForWindow(2000);
        return driver.findElement(By.cssSelector("div.el-row:nth-child(4) > " +
                "div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > " +
                "div:nth-child(1) > input:nth-child(1)")).getAttribute("value");
    }

    @Override
    //输入职称
    public StaffPage inputJobTitle(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[11]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[11]")).sendKeys(keys);
        return this;
    }

    @Override
    //修改职称
    public StaffPage editJobTitle(String keys){
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[11]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputJobTitle(keys).confirmAdd();
        return this;
    }

    @Override
    //获取职称
    public String getJobTitle(){
        clickEdit();
        waitForWindow(2000);
        return driver.findElement(By.cssSelector("div.el-row:nth-child(4) > div:nth-child(2) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > input:nth-child(1)")).getAttribute("value");
    }

    //绑定督导--only咨询师
    public StaffPage selectSupervisor(String keys){
        waitForWindow(2000);
        //空则不选择督导
        if(keys == "") {
        }
        else{
            //下拉
            driver.findElement(By.xpath("(//input[@type='text'])[8]")).click();
            driver.findElement(By.cssSelector("div.el-select-dropdown:nth-child(11) > div:nth-child(1) > div:nth-child(1) > " +
                    "ul:nth-child(1) > li:nth-child(1)")).click();
            driver.findElement(By.cssSelector(".counselorAddModal")).click();
        }
        return this;
    }

    public String getSupervisor(){
        waitForWindow(2000);
        clickEdit();
        waitForWindow(2000);
        //获取当前督导绑定框内的值
        return driver.findElement(
                By.cssSelector("div.el-select:nth-child(1) > div:nth-child(1) > input:nth-child(1)")).getAttribute("value");
    }

    //新增咨询师 输入信息的方法 9个参数
    public String inputAll(String name, String phoneNum, String ID,
                           String Email,String quality,String workplace, String jobTitle,
                           String username, String password){
        inputName(name).
                inputPhoneNum(phoneNum).
                inputID(ID).
                inputEMail(Email);
                selectSupervisor(quality).
                inputWorkPlace(workplace).
                inputJobTitle(jobTitle).
                inputUsername(username).
                inputPassword(password);
        confirmAdd(); //最后点击确认添加
        String info = getErrorMessage();
        return info;
    }

    /**
     * 用于维护 所有错误提示信息的输出，重写getErrorMessage
     * 因为有10个输入框，因此有10个错误提示消息的维护
     * @return
     */
    @Override
    public String getErrorMessage() {
        waitForWindow(2000);
        String info = "";
        //name错误提示消息的css选择器
        By.ByCssSelector nameError = new By.ByCssSelector(".el-row:nth-child(1) > .el-col:nth-child(1) .el-form-item__error");
        if(isElementExist(driver,nameError)){
            WebElement element = driver.findElement(nameError);
            waitForWindow(500);
            String text = "姓名：" + element.getText();
            info = info + (text + '\n');
        }

        //phoneNum错误提示消息的css选择器
        By.ByCssSelector phoneNumError = new By.ByCssSelector(".el-row:nth-child(1) > .el-col:nth-child(2) .el-form-item__error");
        if(isElementExist(driver,phoneNumError)){
            WebElement element = driver.findElement(phoneNumError);
            waitForWindow(500);
            String text = "电话：" + element.getText();
            info = info + (text + '\n');
        }

        //ID错误提示消息的css选择器
        By.ByCssSelector IDError = new By.ByCssSelector(".el-row:nth-child(2) .el-form-item__error");
        if(isElementExist(driver,IDError)){
            WebElement element = driver.findElement(IDError);
            waitForWindow(500);
            String text = "身份证号：" + element.getText();
            info = info + (text + '\n');
        }

        //Email错误提示消息的css选择器
        By.ByCssSelector EmailError = new By.ByCssSelector(".el-row:nth-child(3) > .el-col:nth-child(1) .el-form-item__error");
        if(isElementExist(driver,EmailError)){
            WebElement element = driver.findElement(EmailError);
            waitForWindow(500);
            String text = "邮箱：" + element.getText();
            info = info + (text + '\n');
        }

        //selectSupervisor错误提示消息的css选择器
        By.ByCssSelector JobTitleError = new By.ByCssSelector(".el-row:nth-child(3) > .el-col:nth-child(2) .el-form-item__error");
        if(isElementExist(driver,JobTitleError)){
            WebElement element = driver.findElement(JobTitleError);
            waitForWindow(500);
            String text = "绑定督导：" + element.getText();
            info = info + (text + '\n');
        }

        //workSpace错误提示消息的css选择器
        By.ByCssSelector workSpaceError = new By.ByCssSelector(".el-row:nth-child(4) > .el-col:nth-child(1) .el-form-item__error");
        if(isElementExist(driver,workSpaceError)){
            WebElement element = driver.findElement(workSpaceError);
            waitForWindow(500);
            String text = "工作单位：" +element.getText();
            info = info + (text + '\n');
        }

        //QualityNum错误提示消息的css选择器
        By.ByCssSelector jobTitleError = new By.ByCssSelector(".el-row:nth-child(4) > .el-col:nth-child(2) .el-form-item__error");
        if(isElementExist(driver,jobTitleError)){
            WebElement element = driver.findElement(jobTitleError);
            waitForWindow(500);
            String text = "职称：" +element.getText();
            info = info + (text + '\n');
        }

        //Username错误提示消息的css选择器
        By.ByCssSelector UsernameError = new By.ByCssSelector(".el-row:nth-child(5) .el-form-item__error");
        if(isElementExist(driver,UsernameError)){
            WebElement element = driver.findElement(UsernameError);
            waitForWindow(500);
            String text = "用户名：" +element.getText();
            info = info + (text + '\n');
        }

        //Password错误提示消息的css选择器
        By.ByCssSelector PasswordError = new By.ByCssSelector(".el-row:nth-child(6) .el-form-item__error");
        if(isElementExist(driver,PasswordError)){
            WebElement element = driver.findElement(PasswordError);
            waitForWindow(500);
            String text = "密码：" +element.getText();
            info = info + (text + '\n');
        }
        waitForWindow(2000);
        return info;
    }


}
